﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;

namespace TV_Organizer.Subtitles
{
    public class Subtitle : DependencyObject
    {
        public event EventHandler<EventArgs> IsSelectedChanged;

        public Subtitle()
        {
            if (!Application.Current.Dispatcher.CheckAccess())
                throw new InvalidOperationException("Subtitle: Constructor must be called from the dispatcher thread.");

            DependencyPropertyDescriptor.FromProperty(IsSelectedProperty, typeof(Subtitle)).AddValueChanged(this, OnIsSelectedChanged);
        }

        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(Subtitle), new UIPropertyMetadata(false));
        public bool IsSelected
        {
            get { return this.SafelyGetValue<bool>(IsSelectedProperty); }
            set { this.SafelySetValue(IsSelectedProperty, value); }
        }

        public static readonly DependencyProperty FilenameProperty = DependencyProperty.Register("Filename", typeof(string), typeof(Subtitle), new UIPropertyMetadata(string.Empty));
        public string Filename
        {
            get { return this.SafelyGetValue<string>(FilenameProperty); }
            set { this.SafelySetValue(FilenameProperty, value); }
        }

        public static readonly DependencyProperty LanguageProperty = DependencyProperty.Register("Language", typeof(Language), typeof(Subtitle), new UIPropertyMetadata(Language.Unknown));
        public Language Language
        {
            get { return this.SafelyGetValue<Language>(LanguageProperty); }
            set { this.SafelySetValue(LanguageProperty, value); }
        }

        public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(string), typeof(Subtitle), new UIPropertyMetadata(string.Empty));
        public string Source
        {
            get { return this.SafelyGetValue<string>(SourceProperty); }
            set { this.SafelySetValue(SourceProperty, value); }
        }

        public override string ToString()
        {
            return this.Filename;
        }

        private void OnIsSelectedChanged(object sender, EventArgs e)
        {
            if (this.IsSelectedChanged != null)
                this.IsSelectedChanged(this, new EventArgs());
        }
    }
}
